var e = require("../../../utils/function.js"), a = require("../../../api.js"), t = getApp();

Page({
    data: {
        img: t.img,
        complain: "",
        name: "",
        phone: "",
        order_no: "",
        is_upload: !1,
        upload_type: 0,
        upload_img: []
    },
    complainInput: function(a) {
        var t = a.detail.value;
        e.regTest(t, "请输入您要投诉的内容");
        this.setData({
            complain: t
        });
    },
    nameinput: function(e) {
        var a = e.detail.value;
        this.setData({
            name: a
        });
    },
    phoneinput: function(e) {
        var a = e.detail.value;
        this.setData({
            phone: a
        });
    },
    getComplain: function() {
        var o = this, i = this.data, n = i.complain, s = i.name, r = i.phone, d = e.regTest(n, "请输入您要投诉的内容"), p = e.regTest(s, "请输入您的姓名"), u = e.regTest(r, "请输入您的电话", /^1\d{10}$/);
        if (d && p && u) t.request({
            url: a.user.complaints,
            method: "post",
            data: {
                order_no: o.data.order_no,
                content: o.data.complain,
                name: o.data.name,
                phone: o.data.phone,
                img: o.data.upload_img
            },
            success: function(e) {
                1 == e.code ? wx.redirectTo({
                    url: "../../map/orderGoing/orderGoing?order_no=" + o.data.order_no
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                });
            }
        }); else var d = e.regTest(n, "请输入您要投诉的内容"), p = e.regTest(s, "请输入您的姓名"), u = e.regTest(r, "请输入您的电话", /^1\d{10}$/);
    },
    onLoad: function(e) {
        this.setData({
            order_no: e.order_no
        }), e.uid && t.shareCouponsMessage(e.uid);
    },
    open_upload: function() {
        this.setData({
            is_upload: !0
        });
    },
    close_upload: function() {
        this.setData({
            is_upload: !1
        });
    },
    upload_img: function() {
        var e = this;
        wx.chooseImage({
            count: 3,
            success: function(a) {
                e.setData({
                    upload_type: 1
                }), a.tempFilePaths.length > 3 && wx.showTabBar({
                    title: "最多只能上传3张图片",
                    icon: "none"
                });
                for (var t = 0; t < a.tempFilePaths.length; t++) e.uploadFile(a.tempFilePaths[t]);
            }
        });
    },
    uploadFile: function(e) {
        var o = this.data.upload_img, i = this;
        wx.uploadFile({
            url: a.order_comment.multimedia,
            filePath: e,
            name: "file",
            formData: {
                access_token: wx.getStorageSync("access_token"),
                _uniacid: t.siteInfo.uniacid,
                _acid: t.siteInfo.acid
            },
            success: function(e) {
                var a = JSON.parse(e.data);
                console.log(a.data, "2222222222"), o.push(a.data), i.setData({
                    upload_img: o
                });
            }
        });
    },
    onShareAppMessage: function() {
        return {
            title: t.shareAppMessage().title,
            imageUrl: t.shareAppMessage().imageUrl,
            desc: t.shareAppMessage().desc,
            path: t.shareAppMessage().path
        };
    }
});